#!/bin/bash

# 设置 libzmq 路径
LIBZMQ_PATH="libs/libzmq-master"

# 检查并删除现有的 build 文件夹
if [ -d "$LIBZMQ_PATH/build" ]; then
    rm -rf "$LIBZMQ_PATH/build"
fi

# 检查是否存在 CMakeLists.txt 文件
if [ ! -f "$LIBZMQ_PATH/CMakeLists.txt" ]; then
  echo "错误：未找到 CMakeLists.txt 文件，请确保已正确克隆 libzmq 仓库到 $LIBZMQ_PATH"
  exit 1
fi

# 创建并进入 build 目录
mkdir -p "$LIBZMQ_PATH/build" && cd "$LIBZMQ_PATH/build"

# 配置 CMake
cmake ..

# 检查 CMake 是否成功
if [ $? -ne 0 ]; then
  echo "CMake 配置失败"
  exit 1
fi

# 编译 libzmq
make -j$(nproc)

# 检查编译是否成功
if [ $? -eq 0 ]; then
  echo "libzmq 编译成功"
else
  echo "libzmq 编译失败"
  exit 1
fi
